import socket
import select
class socket_thread:
    #socket_hand=""
    def __init__(self,id,hostname,port):
        self.id=id
        self.hostname=hostname
        self.port=port
        self.socket_hand = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
    def connect(self):
        print "initiate socket:",self.id
        #client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            self.socket_hand.connect((self.hostname, int(self.port)))
            return self.socket_hand
        except socket.error, msg:
            self.socket_hand.close()
    def send(self,data):
        self.socket_hand.send(data.decode('hex'))
        print "socket send data:",self.id
    def recv(self):
        data=self.socket_hand.recv(2048)
        print "socket ",self.id," received response: ",data
        return data
                
'''
Created on 2011-03-14

@author: user1
'''
